#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: init_config.py 
@version:
@time: 2022/03/01 
"""
from TapClientCore.T01_init_conf.init import *
import os

__all__ = [
    'useage',
    'serve_collection',
    'datasource_collection',
    'dataflow_collection',
    'parallel_record_collection',
    'task_collection',
    'inspects_collection',
    'requests_retime',
    'rerun',
    'interval',
    'timeout_config',
    'linux_info',
    'MFA',
    'config',
]
useage = {}
path = os.getcwd().split('/')
if 'parallel' in path:
    useage = {
        'useage': 'local',
        'tapdataVersion': 'v2'
    }
elif 'jenkins_exec_machine_space' in path:
    useage = {
        'useage': 'cloud',
        'tapdataVersion': 'v2'
    }
else:
    useage = read_yaml(PathConf.V2_YML).get('Useage')
serve_template = read_yaml(PathConf.SERVE_TEMPLATE)
print(path)

# useage
dbs = MFA.show_dbs()
if mongodb_setting.get('db') not in dbs:
    MFA.insert_one(serve_collection, serve_template)
collections = MFA.show_collections()
if serve_collection not in collections:
    MFA.insert_one(serve_collection, serve_template)
if not MFA.query(serve_collection, useage):
    MFA.insert_one(serve_collection, serve_template)
config = MFA.query(serve_collection, useage)[0]
if config.get('serve')[-1] == "/":
    config["serve"] = config["serve"][0:-1]
if config.get('apiserve') is None:
    print('not apiserve config')
else:
    if config.get('apiserve')[-1] == "/":
        config["apiserve"] = config["apiserve"][0:-1]
print(config)
